package com.atguigu.yygh.hosp.controller;

import com.atguigu.yygh.common.result.Result;
import com.atguigu.yygh.hosp.service.HospitalService;
import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author ybl
 * @version 1.9
 * @date 2021/5/18 12:01
 */
@Api(tags = "医院管理接口")
@RestController
@RequestMapping("/admin/hosp/hospital")
public class HospitalController {

  @Autowired
  private HospitalService hospitalService;

  //根据id获取医院详情
  @ApiOperation(value = "根据id获取医院详情")
  @GetMapping("showDetail/{id}")
  public Result showDetail(@PathVariable String id){
    Map<String, Object> stringObjectMap = hospitalService.showHospDetail(id);
    return Result.ok(stringObjectMap);
  }

  // 更新医院上下线
  @ApiOperation(value = "更新医院上下线")
  @GetMapping("lock/{id}/{status}")
  public Result lock(@PathVariable String id,@PathVariable Integer status){
    hospitalService.lock(id,status);
    return Result.ok();
  }

  // 获取分页列表
  @ApiOperation("获取分页列表")
  @GetMapping("list/{pageNum}/{pageSize}")
  public Result index(@PathVariable("pageNum") Integer pageNum,
                      @PathVariable("pageSize") Integer pageSize,
                      HospitalQueryVo hospitalQueryVo){

    // 调用接口查询
    Page<Hospital> page = hospitalService.findHospitalPage(pageNum,pageSize,hospitalQueryVo);

    return Result.ok(page);
  }
}
